package com.zdy.im.user.controller;



import java.util.ArrayList;
import java.util.List;

import com.sixeco.framework.common.api.ApiDoc;
import com.sixeco.framework.common.data.BasePage;
import com.sixeco.framework.http.data.vo.HttpRequestByIdVo;
import com.sixeco.framework.http.data.vo.ResponseResultList;
import com.sixeco.framework.http.handler.OutputResponse;
import com.zdy.im.user.dto.request.ImMessageReadRequestDto;
import com.zdy.im.user.dto.response.ImMessageReadResponseDto;
import com.zdy.im.user.facade.ImMessageReadFacade;
import com.zdy.im.user.service.ImMessageReadService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.beans.factory.annotation.Autowired;


import com.zdy.im.user.vo.request.ImMessageReadQueryRequestVo;
import com.zdy.im.user.vo.response.ImMessageReadShowResponseVo;

/**
 * @Title: ImMessageReadController.java
 * @Author 作者 : zdy
 * @CreateDate 创建时间: 2021-02-30
 * @version V1.0
 *  <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容:
 * </pre>
 * @Description: TODO(说明) 对象缓存统一模板实现类;
 */
@ApiDoc(
        module = "消息状态表模块", isApp = true
)
@Controller
public class ImMessageReadController {

    @Autowired
    private ImMessageReadFacade imMessageReadFacade;

    @Autowired
    private ImMessageReadService imMessageReadService;

    public interface UrlCommand{
        public static final String user_imMessageRead_pageList = "/user/immessageread/pageList";
        public static final String user_imMessageRead_info = "/user/immessageread/info";
    }

    /**
    * @Title: test测试生成类分页信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "分页获取消息状态表信息",
            request = ImMessageReadQueryRequestVo.class,
            response = ImMessageReadShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imMessageRead_pageList, method = RequestMethod.GET)
    public void list(OutputResponse out, ImMessageReadQueryRequestVo imMessageReadQueryRequestVo){
            ImMessageReadRequestDto imMessageReadRequestDto = ImMessageReadRequestDto.build( ).clone(imMessageReadQueryRequestVo);

        BasePage page =  BasePage.build().toPageSize(imMessageReadQueryRequestVo.getPageSize()).toPageNo(imMessageReadQueryRequestVo.getPageNo());
        page.toParamObject(imMessageReadRequestDto );
        ResponseResultList<ImMessageReadResponseDto> resultList = imMessageReadService.getImMessageReadByNextPage(page);

        if(null == resultList || resultList.getList().isEmpty() ){
            out.writeSuccess();
            return;
        }
        List<ImMessageReadShowResponseVo> listVo = new ArrayList<>();
        resultList.getList().forEach(e -> listVo.add(ImMessageReadShowResponseVo.build().clone(e)));

//        ResponseResultList list =  ResponseResultList.build().toList(listVo)
//                .toIsNextPage(resultList.getIsNextPage())
//                .toPageIndex(resultList.getPageIndex())
//                .setTotal(resultList.getTotal());
//        out.write(list);
    }





    /**
    * @Title: 查看test测试生成类信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "查看消息状态表信息",
            request = HttpRequestByIdVo.class,
            response = ImMessageReadShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imMessageRead_info ,method = RequestMethod.GET)
    public void detail(OutputResponse out, HttpRequestByIdVo idRequestVo){

            ImMessageReadResponseDto imMessageReadResponseDto = imMessageReadService.getImMessageReadById(idRequestVo.getId());
            ImMessageReadShowResponseVo vo =  ImMessageReadShowResponseVo.build().clone(imMessageReadResponseDto);
        out.write(vo);
    }



}
